﻿/***************************************************************
 * 开发人员：网魂小兵@http://www.mozlite.com
 * 
 * 目标标本：4.0.30319.239
 * 
 * 最后修改：2011/12/16 20:13:20
 * ************************************************************/
namespace Mozlite
{
    using System;
    using System.Linq;
    using System.Text;
    using System.Collections.Generic;
    using System.Web.Mvc;
    using Mozlite.Common;
    using Mozlite.Web.UI;

    /// <summary>
    /// 通用区域路由注册。
    /// </summary>
    public class CommonUrls : BaseRouteRegistration
    {
        /// <summary>
        /// 初始化类<see cref="T:Mozlite.Web.UI.CommonUrls"/>。
        /// </summary>
        public CommonUrls() { }

        /// <summary>
        /// 注册通用路由。
        /// </summary>
        /// <param name="routes">路由集合。</param>
        public override void RouteRegister(System.Web.Routing.RouteCollection routes)
        {
            routes.BeginRegister();
            /*dialog*/
            routes.Register("dialog_postview", "dialog/postview", new { controller = "dialog", action = "postview" });

            //common
            routes.Register("common_threadviewbyid", "thread/{id}/view", new { controller = "home", action = "threadview" }, new { id = "[0-9]+" }, new[] { "Mozlite.Web.UI.WOW.Controllers" });
            routes.Register("common_threadviewbykey", "thread/{key}/view", new { controller = "home", action = "threadview" }, new { key = "[a-z0-9\\-_]+" }, new[] { "Mozlite.Web.UI.WOW.Controllers" });
            routes.Register("common_categoriesviewbyid", "threads/{id}/view", new { controller = "home", action = "threadsview" }, new { key = "[0-9]+" }, new[] { "Mozlite.Web.UI.WOW.Controllers" });
            routes.Register("common_categoriesviewbykey", "threads/{key}/view", new { controller = "home", action = "threadsview" }, new { key = "[a-z0-9\\-_]+" }, new[] { "Mozlite.Web.UI.WOW.Controllers" });
            
            //media
            routes.Register("media_threadviewbyid", "media/{id}/view", new { controller = "home", action = "threadview" }, new { id = "[0-9]+" }, new[] { "Mozlite.Web.UI.WOW.Controllers" });
            routes.Register("media_threadviewbykey", "media/{key}/view", new { controller = "home", action = "threadview" }, new { key = "[a-z0-9\\-_]+" }, new[] { "Mozlite.Web.UI.WOW.Controllers" });
            routes.Register("media_categoriesviewbyid", "medias/{id}/view", new { controller = "home", action = "threadsview" }, new { key = "[0-9]+" }, new[] { "Mozlite.Web.UI.WOW.Controllers" });
            routes.Register("media_categoriesviewbykey", "medias/{key}/view", new { controller = "home", action = "threadsview" }, new { key = "[a-z0-9\\-_]+" }, new[] { "Mozlite.Web.UI.WOW.Controllers" });

            //文件访问地址
            routes.Register(FileBrowser_Name, "filestorages/browser/{fileid}", new { controller = "filestorages", action = "filebrowser", fileid = UrlParameter.Optional });
            routes.RegisterControllerAction("Account", "logon", ApplicationType.UCenter);
            routes.RegisterControllerAction("Account", "register", ApplicationType.UCenter);
            routes.RegisterControllerAction("Account", "logout", ApplicationType.UCenter);
        }
        /// <summary>
        /// 登录。
        /// </summary>
        private const string Logon_Name = "account_logon";
        /// <summary>
        /// 退出。
        /// </summary>
        private const string Logout_Name = "account_logout";
        /// <summary>
        /// 注册。
        /// </summary>
        private const string Register_Name = "account_register";
        /// <summary>
        /// 文件访问。
        /// </summary>
        private const string FileBrowser_Name = "filebrowser";

        /// <summary>
        /// 登录。
        /// </summary>
        public static string Logon { get { return  FormatUrl(Logon_Name); } }
        /// <summary>
        /// 退出。
        /// </summary>
        public static string Logout { get { return FormatUrl(Logout_Name); } }
        /// <summary>
        /// 注册。
        /// </summary>
        public static string Register { get { return FormatUrl(Register_Name); } }
        /// <summary>
        /// 文件访问。
        /// </summary>
        /// <param name="fileID">文件ID。</param>
        /// <returns>返回文件访问的URL地址。</returns>
        public static string GetFileBrowser(int fileID)
        {
            if (fileID > 0)
                return FormatUrl(FileBrowser_Name, new { fileid = fileID });
            return FormatUrl(FileBrowser_Name) + "/";
        }
        /// <summary>
        /// 后台管理URL地址。
        /// </summary>
        public static string CPDefaultUrl { get { return  Mozlite.Web.UI.Areas.ControlPanel.CUrls.DefaultUrl; } }
        /// <summary>
        /// 用户中心默认URL地址。
        /// </summary>
        public static string UCDefaultUrl { get { return Mozlite.Web.UI.Areas.UCenter.UCenterUrls.DefaultUrl; } }

        /// <summary>
        /// 首页地址。
        /// </summary>
        public static string DefaultUrl { get { return RouteManager.GetDefaultUrl(null); } }
    }
}